<template>
	<view class="catalog">
		<view class="catalog_title">课程目录大纲</view>
		<view class="catalog_list_box">
			<view class="catalog_item" v-for="(item,index) in courseChapterList" :key="index" @tap="goChapterDetails(item.courseId,item.id)">
				<view class="catalog_name">{{item.chapterName}}</view>
				<view class="catalog_type">
					<text v-if="item.chapterWay == 1">[图文]</text>
					<text v-if="item.chapterWay == 0">[视频]</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { useUserStoreToRefs } from '@/store/useUserStore';
	import api from '@/api'
	const { userInfo } = useUserStoreToRefs();
	const props = defineProps({
	    courseChapterList:{
	        type:Object,
	        default:[]
	    },
		couresStatus: {
			type:[Number,String],
			default:1
		},
		viewTheCrowd: {
			type:[Number,String],
			default:0
		},
		couresId: {
			type:[Number,String],
			default:''
		},
		getCourseDetails: {
			type: Function
		}
	})
	const goChapterDetails = async (courseId : any, chapterId : any) => {
		const res : any = await api({
			method: 'get',
			url: `/mall/studio/petsitter-team/getMyInfo`
		})
		const resCheck : any = await api({
			method: 'get',
			url: `/mall/course/course/${props.couresId}`
		})
		if(props.couresStatus == 2 || resCheck.data.status == 2) {
			toastfnc('课程已下架/删除')
			await props.getCourseDetails(props.couresId)
			return
		} 
		if( props.viewTheCrowd != 0) {
			if(props.viewTheCrowd == 1 && res.data.identity == 2) {
				return toastfnc('本课程仅限陪宠师查看')
				
			}
			if (props.viewTheCrowd == 2 && res.data.identity == 1 && res.data.orderTakingRight != 1) {
				return toastfnc('本课程仅限未获取接单权的陪宠师查看')
			}
			/* viewTheCrowd查看人群:0-不限制;1-仅陪宠师;2-未获取接单权的陪宠师
			identity orderTakingRight   接单权 0-待获得;1-已获取;2-已关闭 */
		}
		uni.navigateTo({
			url: `/pages/businessSchool/chapterDetails/chapterDetails?courseId=${courseId}&chapterId=${chapterId}`
		})
		
	}
	const toastfnc = (tipsText : string) => {
		uni.showToast({
			title: tipsText,
			icon: 'none'
		})
	
	}
</script>

<style lang="scss" scoped>
	.catalog {
		margin: 0 auto;
		padding-top: 48rpx;
		width: 686rpx;
	}

	.catalog_title {
		margin-bottom: 40rpx;
		line-height: 1;
		font-size: 32rpx;
		color: #1A1A1A;
		font-weight: bold;
	}

	.catalog_list_box {
		padding: 8rpx 32rpx;
		background-color: #fff;
		border-radius: 24rpx;

		.catalog_item {
			padding-bottom: 40rpx;
			margin-top: 40rpx;
			border-bottom: 1rpx dashed #E6E6E6;

			.catalog_name {
				margin-bottom: 14rpx;
				font-size: 28rpx;
				color: #5C5E5E;
				line-height: 1.2;
			}

			.catalog_type {
				font-size: 22rpx;
				color: #7C807F;
				line-height: 1;
			}
		}

		.catalog_item:last-child {
			border: none;
		}
	}
</style>